<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.checkbox.php
 * Type:     function
 * Name:     checkbox
 * Purpose:  outputs html for a form checkbox
 * -------------------------------------------------------------
 */
function smarty_function_checkbox($params, &$smarty) {
    $object = $smarty->_tpl_vars[$params['object']];
    $mapping = $params['object'] . '.' . $params['name'];
    $value = @isset($params['value']) ? $params['value'] : true;
	$parameter = $params['name'];
	$checked = @$params['checked'] == true || $object->$parameter == $value;
	
    $html .= '<input type="checkbox" name="' . $mapping . '" id="' . $mapping . '"';
    $html .= ' value="' . $value . '" ' . ($checked ? 'checked="true"' : '') . ' /> ';
    if(@$params['label'] != '') {
        $html .= '<label>';
        $html .= $params['required'] == true ? '<em>*</em>' : '';
        $html .= $params['label'] . '</label>';
    }
    return $html;
}
?>